const query = require('../utils/conn');

// module.exports = (router) =>{ 
//         router.get('/yinshi', (req, res) => {
        
//         let sql = 'select * from yinshi'


//            query(sql).then(result => {

//         res.render('yinshi', { yinshi: result })
//     })
//             
//         })
    
//     }


module.exports = (router) =>{ 
      router.get('/yinshi', async (req, res) => {
    // let currentyinshi = req.query.yinshi ? req.query.yinshi : 1;
    let {yinshi = 1} = req.query;
    let length = 12;
    let data_count = `select count(text) 'number' from yinshi`
    let totalyinshi = await query(data_count)
    let yinshiCount = Math.ceil(totalyinshi[0].number / length);
    // console.log('yinshi',totalyinshi[0].number)
  //    let sql = 'select * from yinshi limit 12';
    let sql = `select * from yinshi limit ${(yinshi -1 ) * length},${length}`;
     let yinshiNumber = await query(sql)

    res.render('yinshi', { totalyinshi: totalyinshi ,yinshi:yinshiCount, yinshiNumber:yinshiNumber, currentyinshi:yinshi})
          
 })
}